package com.yf.exam.modules.trainingarchives.evaluation.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yf.exam.common.entity.Result;
import com.yf.exam.modules.trainingarchives.evaluation.dto.EvaluationSummaryDTO;
import com.yf.exam.modules.trainingarchives.evaluation.entity.EvaluationSummary;
import com.yf.exam.modules.trainingarchives.evaluation.mapper.EvaluationSummaryMapper;
import com.yf.exam.modules.trainingarchives.evaluation.service.IEvaluationSummaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yf.exam.modules.trainingarchives.evaluation.vo.EvaluationSummaryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 满意度调查总结表 服务实现类
 * </p>
 *
 * @author lql
 * @since 2025-01-16
 */
@Service
public class EvaluationSummaryServiceImpl extends ServiceImpl<EvaluationSummaryMapper, EvaluationSummary> implements IEvaluationSummaryService {

    @Override
    public void add(EvaluationSummaryDTO reqDTO) {
        EvaluationSummary evaluationSummary = new EvaluationSummary();
        BeanUtils.copyProperties(reqDTO, evaluationSummary);
        this.saveOrUpdate(evaluationSummary);
    }

    @Override
    public EvaluationSummaryVO get(EvaluationSummaryDTO reqDTO) {
        EvaluationSummary evaluationSummary = this.getOne(Wrappers.<EvaluationSummary>lambdaQuery()
                .eq(EvaluationSummary::getTrainingClassInfoId, reqDTO.getTrainingClassInfoId())
                .eq(EvaluationSummary::getType, reqDTO.getType()));
        EvaluationSummaryVO vo = new EvaluationSummaryVO();
        if (evaluationSummary == null) {
            vo.setType(reqDTO.getType());
            vo.setTrainingClassInfoId(reqDTO.getTrainingClassInfoId());
            return vo;
        }

        BeanUtils.copyProperties(evaluationSummary,vo);
        return vo;
    }


}
